package ge.modules.physics;

import ge.engine.Engine;
import ge.engine.Log;
import ge.exceptions.FunctionNonSuported;
import ge.lowlevel.box2d.FactoryBox2D;
import ge.modules.Module;

public class PhysicWorldModule implements Module
{
	private boolean simulation;
	public PhysicWorldModule(double xGravity, double yGravity, double minVertex,double maxVertex,boolean doSleep,double scale)
	{
		FactoryBox2D.get().newWorld(xGravity,yGravity,minVertex,maxVertex,doSleep,scale);
		simulation = false;
	}

	@Override
	public void update()
	{
		
		if(!simulation)
			return;
		
	
		if(Engine.fps() < Engine.getFps()/4)
		{
			Log.write("Simulacion fisica abortada: "+Engine.fps()+"/"+(Engine.getFps()/4));
			return;
		}	
		try {
			FactoryBox2D.getActualWorld().step(Engine.tick()/1000.0, 1);
		} catch (FunctionNonSuported e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void enableSimulation(boolean enable)
	{
		simulation = enable;
		Log.write("Comienza Simulacion");
	}
	@Override
	public void draw() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void delete() {
		// TODO Auto-generated method stub
		
	}
}
